package com.itheima.edu.info.manager.dao;

import com.itheima.edu.info.manager.domain.Student;

public class StudentDao {
    private static Student[] students = new Student[5];
    //查找所有学生信息
    public Student[] findAllStudent() {
        return students;
    }
    //添加学生
    public boolean addStuendt(Student student) {
        //遍历判断数组是否已满
        //标记为index
        int index = -1;
        for (int i = 0; i < students.length; i++) {
            if(students[i] == null){
                index = i;
            }
        }
        //未满则记录索引值将记录数组位置添加学生再返回true,满了就直接返回false
        if(index!=-1){
            students[index] = student;
            return true;
        }else{
            return false;
        }
    }
    //删除学生
    public void deleteStundetById(String delId) {
        int index =getIndex(delId);
        students[index] = null;
    }
    //录入学生ID方法
    public int getIndex(String delId) {
        int index = -1;
        for (int i = 0; i < students.length; i++) {
            if(students[i] != null){
                index = i;
            }
        }
        return index;
    }
    //修改学生
    public void updateStudent(Student student) {
        int index = getIndex(student.getId());
        //修改覆盖
        students[index] = student;
    }
}
